<template lang="pug">
  .clearfix
    Modal(
      width="400"
      v-model="isShowBackModal"
      title="退回"
      class-name="vertical-center-modal"
    )
      .search-form.mb-10.pr-10
        Form.ivu-row.ivu-form-basic(ref="formData" :model="formData" :rules="rules" :label-width="90")
          FormItem.form-item.ivu-col.pr-20.mb-15(v-for="(item, index) of formItem" :label="item.label" :key="index" :class="item.style" :prop="item.prop")
            template(v-if="item.type === 'input'")
              Input(v-model="formData[item.model]" :placeholder="item.placeholder" clearable)

      .clearfix(slot="footer")
        Button(type="text" @click="cancel") 取消
        Button(type="primary" @click="handleSubmit" :loading="!isCanSubmit") 确定
</template>

<script>
import { CustomerSalaryApi } from '@/api/CustomerSalary.api.js'
import { Common } from '@/utils/common.js'
export default {
  name: '',

  data () {
    return {
      isShowBackModal: false,
      formData: {
        backReason: ''
      },
      formItem: [
        { type: 'input', label: '退回原因：', placeholder: '请输入退回原因', prop: 'backReason', model: 'backReason', style: 'ivu-col-span-24' },
      ],
      rules: {
        backReason: [{ required: true, message: '请输入退回原因' }]
      },
      isCanSubmit: true,
      parentRow: null
    }
  },

  watch: {
  },

  mounted () {
  },

  methods: {
    cancel () {
      this.isShowBackModal = false
    },

    show (row) {
      this.parentRow = row
      this.isCanSubmit = true
      this.isShowBackModal = true
      this.$refs.formData.resetFields()
    },

    async handleSubmit () {
      var params = {
        ID: this.parentRow.id,
        Year: this.$moment(this.parentRow.salaryMonth).format('YYYY'),
        BackReason: this.formData.backReason
      }
      console.log('params: ', params)
      this.$refs.formData.validate((valid) => {
        if (valid) {
          console.log('提交表单', params)          
          CustomerSalaryApi.back(params).then(res => {
            if (res.data.success) {
              this.$Message.success(res.data.message)
            } else {
              this.$Message.error({
                content: res.data.message,
                duration: 10,
                closable: true
              })
            }
            this.query()
          })
        }
      })
    }
  }
}
</script>

<style lang="less" scope>
</style>
